package com.lv.suyiyong.hfr.adapter

import android.view.View
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.common.ktx.LoadSrc
import com.lv.common.ktx.priceSmallDot
import com.lv.common.ktx.setBname
import com.lv.common.utils.ARoutUtils
import com.lv.common.utils.Constants
import com.lv.common.utils.MoneyUtil
import com.lv.service.bean.SearchGoodsBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.databinding.ItemGoodsHomeSearchBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class SearchGoodsAdapter(
    private val datas: MutableList<SearchGoodsBean>,
) :
    BaseQuickAdapter<SearchGoodsBean, DataBindBaseViewHolder>
        (R.layout.item_goods_home_search, datas) {

    override fun convert(holder: DataBindBaseViewHolder, item: SearchGoodsBean) {
        val mBinding: ItemGoodsHomeSearchBinding =
            holder.getBind() as ItemGoodsHomeSearchBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        mBinding.ivImg.LoadSrc(item.image)

//        val labs = item.label
//        //只有金牌店铺显示，其它不显示
//        val benefit = item.benefit
//        if (benefit == "1") {
//            mBinding.tvGoodsName.setTextTag(R.drawable.icon_hui_tag, item.name ?: "")
//        } else {
        mBinding.tvGoodsName.text = item.name
//        }
        mBinding.ivGold.visibility = if (item.isspecially == "2") View.VISIBLE else View.GONE
        mBinding.ivGold.LoadSrc(Constants.GOLD_TAG_SMALL)
        val access = MoneyUtil.formatMoneyW(item.access ?: 0).priceSmallDot()
        mBinding.tvScen.text = "${access}人浏览"
        mBinding.ivArrow.LoadSrc("https://suyiyong.oss-cn-hangzhou.aliyuncs.com/iOS/projectPic/hfr/search_toUp.png")
        item.merito?.setBname(tag = "  ", tvBname = mBinding.tvBname)

        mBinding.clContainer.setOnClickListener {
            ARouter.getInstance().build(ARoutUtils.GoodsDetilsActivity).withString("spuid", item.id)
                .navigation()
            onViewClickListener?.onClick(layoutPosition, item)
        }


    }

    var onViewClickListener: OnPositionTListener<SearchGoodsBean>? = null


}